Post

Replies

Boosts

Views

Activity

Reply to How to change text in SwiftUI conditional button to systemImage?
You're calling a Button initializer that expects a String as its first parameter. Instead, you need to use a different initializer to provide the button's content. To actually change the symbol being used, you can use the .symbolVariant modifier to switch between a variant of .fill and a variant of .none.         .toolbar {             ToolbarItem(placement: .navigationBarTrailing) {                 Button {                     if favorites.contains(item) {                         favorites.remove(item)                     } else {                         favorites.add(item)                     }                 } label: {                 Image(systemImage: "heart")                 .symbolVariant(favorites.contains(item) ? .fill : .none)                 }             }         }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22